﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace E1_eMart
{
    public partial class HandleAddComment : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request["id"] == null || Request["CommentContent"] == null)
            {
                return;
            }
            DataClasses1DataContext edata = new DataClasses1DataContext();
            Comment c = new Comment();
            TaiKhoan tk = new TaiKhoan();
            try
            {            
                //Add database
                if (Session["username"] != null)
                {
                    if (!String.IsNullOrEmpty(Request["CommentContent"]))
                    {
                        c.NoiDungComment = Request["CommentContent"];
                        c.NgayComment = DateTime.Now;
                        tk = (TaiKhoan)Session["username"];
                        c.MaTaiKhoan = tk.MaTaiKhoan;
                        int maSP = int.Parse(Request["id"]);
                        c.MaSanPham = maSP;
                        edata.Comments.InsertOnSubmit(c);
                        edata.SubmitChanges();

                        String s = tk.TenTaiKhoan + " (" + c.NgayComment + "):    " + c.NoiDungComment;                                          
                        Response.Write(s);                        
                    }
                }
            }
            catch (Exception ex)
            {
                return;
            }
        }
    }
}